home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / microcrn / issue_46.arc / ISR.ARC / ISR.H < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-11  |  2.0 KB  |  81 lines

  1. /*    ISR.h -  support for writing interrupt handlers
  2.  
  3.         Supports ISR article in Micro Cornucopia Magazine Issue #46
  4. */
  5.  
  6. #ifndef uchar
  7. #include <defs.h>
  8. #endif
  9.  
  10. #ifndef OP_IRET
  11. #include <cpu.h>
  12. #endif
  13.  
  14. #ifndef AX
  15. #include <call.h>
  16. #endif
  17.  
  18. #define ISR_HDR_LOADED
  19.  
  20. /*    REGS  - Structure of a register file.
  21.  
  22.     A far pointer to this structure is passed to the 
  23.     interrupt handlers by the traps. The CPU registers are
  24.     also passed in the order shown below.
  25.  
  26.     It's therefore possible to declare a handler like this:
  27.  
  28.        void far int_24_handler( isr, r1, r2 )
  29.        isrh *isr;
  30.        __pregs r1, r2;
  31.        {}
  32.  
  33.     Which is much easier to type than the alternative...
  34.     This only works if your compiler supports passing structures
  35.     by value (By now, there probably aren't many that don't...)
  36. */
  37.  
  38. typedef struct ISR_REGS {
  39.   __regdp esbx;
  40.   __reg c;
  41.   __reg3r dsdxax;
  42.   unsigned int di;
  43.   __regdp bpsi;
  44.   __pcreg pc;
  45.   __regpsw psw;
  46. } isr_regs;
  47.  
  48.  
  49. /*    The code to intercept an interrupt and call a 'C function
  50.     is copied into a structure of the following type for each
  51.     handler that's needed. The required patches to the code are
  52.     then made. isr_install() sets up the interrupt vectors,
  53.     and returns. isr_restore() restores the previous handler, and
  54.     isr_pass() calls the previous handler. The code for this trap
  55.     is in ISRHT.C.
  56. */
  57.  
  58. typedef struct ISRH {
  59.    uchar code1[17];
  60.    uint isrhs;
  61.    uchar code2[2];
  62.    uint isrho;
  63.    uchar code3[2];
  64.    void far (*hndlr)();
  65.    uchar code4[11];
  66.    uchar code_jmpf;
  67.    void far (*prev_hndlr)();
  68.    int isr_num;
  69.    int count;
  70.    void far *stack;
  71. } isrh;
  72.  
  73. #define isr_pass(i) ( (i)->code_jmpf= i->prev_hndlr ? OP_JMPF : OP_IRET )
  74. #define isr_iret(i) ( (i)->code_jmpf=                           OP_IRET )
  75. #define isr_retf(i) ( (i)->code_jmpf=                           OP_RETF )
  76.  
  77. void far *isr_get_vector(int inum);
  78. void isr_set_vector(int inum,void far (*farfuncp)());
  79. void isr_install(isrh *isr,int isr_num, void far (*handler)());
  80. void isr_restore(isrh *isr);
  81.